package com.qjs.zzz.test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.qjs.course.service.CoreService;
import com.qjs.course.util.LogUtil;

public class SourceAction extends HttpServlet{
	private  Logger log = LogUtil.getLogger(SourceAction.class.getName());
 	
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {  
    	log.error("---SourceAction..doGet-Start---");
        request.setCharacterEncoding("UTF-8");  
        response.setCharacterEncoding("UTF-8");
        String image=request.getParameter("image");
    	String path=request.getSession().getServletContext().getRealPath("/")+"/WEB-INF/public/image/"+image+".jpg";
    	try {
    		File file=new File(path);
        	FileInputStream fips = new FileInputStream(file);  
        	ByteArrayOutputStream bops = new ByteArrayOutputStream();  
            int data = -1;  
             while((data = fips.read()) != -1){  
                    bops.write(data);  
             }   
            byte[] btImg = bops.toByteArray(); 
            bops.close();
            fips.close();
        	OutputStream out= response.getOutputStream();
            out.write(btImg); 
            out.flush(); 
            out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
    	
    }  


}
